package com.hw.paltfrom.service.doncutor;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hw.paltfrom.exception.HWSystemException;
import com.hw.paltfrom.pojo.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hw.paltfrom.mapper.HwBaseAnnexesfileMapper;
import com.hw.paltfrom.mapper.HwCaseMainMapper;
import com.hw.paltfrom.mapper.HwCasePoliceoperMapper;
import com.hw.paltfrom.mapper.HwCaseSrccomMapper;
import com.hw.paltfrom.mapper.HwCommandTaskMapper;
import com.hw.paltfrom.mapper.HwCommandTaskfeedbackMapper;
import com.hw.paltfrom.mapper.HwDataOverrunstationOverweightMapper;
import com.hw.paltfrom.mapper.HwSupervisionMapper;
import com.hw.paltfrom.rescode.HWSystemCode;
import com.hw.paltfrom.utils.PageUtils;
import com.hw.paltfrom.utils.RandomNumberUtil;
import com.hw.paltfrom.utils.ResponeResultUtil;
import com.hw.paltfrom.vo.CommandTaskCountyVo;
import com.hw.paltfrom.vo.FileInfo;
import com.hw.paltfrom.vo.StandCommandTaskVo;
import com.hw.paltfrom.vo.StepInfoVO;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 指挥调度县 邢家华 2019-11-7 11:01:18
 * 
 * @author Administrator
 *
 */
@Service
public class CountyCommandTaskService {

	@Autowired
	private HwCommandTaskMapper hwCommandTaskMapper;

	@Autowired
	private HwDataOverrunstationOverweightMapper dataOverrunstationOverweightMapper;

	@Autowired
	private HwBaseAnnexesfileMapper hwBaseAnnexesfileMapper;

	@Autowired
	private HwSupervisionMapper hwSupervisionMapper;

	@Autowired
	private HwCaseMainMapper hwCaseMainMapper;

	@Autowired
	private BaseWorkflowService baseWorkflowService;

	@Autowired
	private CommandWorkflowService commandWorkflowService;

	// HW_Case_SrcCom 源头倒查表
	@Autowired
	private HwCaseSrccomMapper hwCaseSrccomMapper;
	// @Autowired HW_Case_PoliceOper 案件交警执法
	@Autowired
	private HwCasePoliceoperMapper hwCasePoliceoperMapper;

	// 指挥调度反馈表 HW_Command_TaskFeedback
	@Autowired
	private HwCommandTaskfeedbackMapper hwCommandTaskfeedbackMapper;

	// 申请查询
	public Map<String, Object> query(CommandTaskCountyVo vo) {

		// 分页
		Integer pageNum = vo.getPageNum();
		Integer pageSize = vo.getPageSize();

		// 筛选条件
		// 车牌号
		String cph = vo.getCph();
		// 任务类型（异地复检01；闯卡移交02；逃逸移交03；举报投诉04；其他05）
		String taskType = vo.getTaskType();
		// 完结、 执行中
		String flowStage = vo.getFlowStage();

		// 县选中的超限站编号
		String overrunCode = vo.getFoverrunCode();
		// 当前登陆县用户的区域id
		String areacode = vo.getfAreacode();
		// 指派中 执行中 字段
		Integer taskClass = vo.getTaskClass();

		EntityWrapper<HwDataOverrunstationOverweight> weightWrapper = new EntityWrapper<HwDataOverrunstationOverweight>();
		if (StringUtils.isNotBlank(cph)) {
			weightWrapper.like("CPH", cph);
		}

		if (StringUtils.isNotBlank(overrunCode)) {
			weightWrapper.eq("F_OverrunCode", overrunCode);
		}

		if (StringUtils.isNotBlank(areacode)) {
			weightWrapper.eq("F_AreaCode", areacode);
		}
		// 分页
		PageUtils<CommandTaskCountyVo> pageUtils = new PageUtils<CommandTaskCountyVo>(pageNum, pageSize);
		// PageHelper.startPage(pageNum, pageSize);
		weightWrapper.orderBy("D_CreateTime", false);
		// 筛选后的称重表
		List<HwDataOverrunstationOverweight> overList = dataOverrunstationOverweightMapper.selectList(weightWrapper);

		// 返回数据集合
		ArrayList<CommandTaskCountyVo> resultList = new ArrayList<CommandTaskCountyVo>();

		for (HwDataOverrunstationOverweight orow : overList) {
			int flag = 0;
			CommandTaskCountyVo resultVo = new CommandTaskCountyVo();

			// 查询当前称重数据 是否有对应的调度数据
			EntityWrapper<HwCommandTask> taskWrapper = new EntityWrapper<HwCommandTask>();
			if (StringUtils.isNotBlank(taskType)) {
				taskWrapper.eq("Task_Type", taskType);
			}

			if (StringUtils.isNotBlank(flowStage)) {
				taskWrapper.eq("Flow_Stage", flowStage);
			} else {
				taskWrapper.ne("Flow_Stage", "08");
			}

			if (taskClass != 0) {
				taskWrapper.eq("Task_Class", taskClass);
			}

			taskWrapper.eq("F_Id", orow.getfId());

			List<HwCommandTask> CommandTaskList = hwCommandTaskMapper.selectList(taskWrapper);

			HwCommandTask entity = new HwCommandTask();
			entity.setfId(orow.getfId());
			HwCommandTask selectOne = hwCommandTaskMapper.selectOne(entity);

			if (!"08".equals(flowStage) && (selectOne != null && selectOne.getFlowStage().equals("08"))) {
				flag = 1;

			}

			HwCommandTask oldCommandTask = null;
			if (!CommandTaskList.isEmpty()) {
				oldCommandTask = CommandTaskList.get(0);
			}

			if (oldCommandTask != null) {

				String oldflowStage = oldCommandTask.getFlowStage();
				String oldtaskType = oldCommandTask.getTaskType();

				// 按钮显示
				// 指派Flow_Stage='02'）的指挥调度任务
				if (oldflowStage.equals("02")) {
					resultVo.setAssigned(1);
				}
				// 完结
				if (oldflowStage.equals("07") && oldtaskType.equals("01")) {
					resultVo.setTheEnd(1);
				}
				// 移交确认
				if (oldflowStage.equals("05") && (oldtaskType.equals("02") || oldtaskType.equals("03"))) {
					resultVo.setTransferConfirmation(1);
				}
				// 上报视频
				if (oldflowStage.equals("07") && (oldtaskType.equals("02") || oldtaskType.equals("03"))) {
					resultVo.setReportTheVideo(1);
				}

			}
			resultVo.setfId(orow.getfId());
			resultVo.setfOverrunname(orow.getfOverrunname());
			resultVo.setCph(orow.getCph());
			resultVo.setdZs(orow.getdZs());
			resultVo.setdZz(orow.getdZz());
			resultVo.setdCxl(orow.getdCxl());
			resultVo.setdJcsj(orow.getdJcsj());
			resultVo.setjZz(orow.getjZz());
			resultVo.setjCxds(orow.getjCxds());
			resultVo.setjJcsj(orow.getjJcsj());
			if (oldCommandTask != null) {
				resultVo.setTaskId(oldCommandTask.getTaskId());
				resultVo.setTaskClass(oldCommandTask.getTaskClass());
				resultVo.setTaskType(oldCommandTask.getTaskType());
				resultVo.setFlowStage(oldCommandTask.getFlowStage());
				resultVo.setFlowCode(oldCommandTask.getFlowCode());
				resultVo.setfAreacode(oldCommandTask.getfAreacode());
				resultVo.setfAccount(oldCommandTask.getfAccount());
				resultVo.setfFromdepcode(oldCommandTask.getfFromdepcode());
				resultVo.setfFromdepname(oldCommandTask.getfFromdepname());
				resultVo.setTaskContent(oldCommandTask.getTaskContent());
			}

			// 20191124新增规则
			// 如果未分类(调度没数据)
			if (flag == 0 && oldCommandTask == null) {
				// 未查扣
				if (orow.getIsSeized() == 0) {

					if (!(flowStage != null && flowStage.equals("08") && oldCommandTask == null)) {
						if (flag == 0) {

							if (StringUtils.isNotBlank(taskType)) {
								if (oldCommandTask != null) {
									resultList.add(resultVo);
								}
							} else {
								resultList.add(resultVo);
							}
						}
					}

				}
			} else {

				if (!(flowStage != null && flowStage.equals("08") && oldCommandTask == null)) {
					if (flag == 0) {

						if (StringUtils.isNotBlank(taskType)) {
							if (oldCommandTask != null) {
								resultList.add(resultVo);
							}
						} else {
							resultList.add(resultVo);
						}
					}
				}

			}

		}
		Object info = pageUtils.getPageResult(resultList);
		// PageInfo<CommandTaskCountyVo> info = new
		// PageInfo<CommandTaskCountyVo>(resultList);
		// info.setTotal(selectCount);
		// info.setPageSize(pageSize);
		return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, info);

	}

	// 指派
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> assigned(CommandTaskCountyVo vo) {

		Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
		wrapper.eq("Task_ID", vo.getTaskId());
		HwCommandTask hwCommandTask = hwCommandTaskMapper.selectById(vo.getTaskId());
		String flowStage = hwCommandTask.getFlowStage();
		String flowCode = hwCommandTask.getFlowCode();
		// 创建基础工作流
		HwBaseWorkflow hwBaseWorkflow = new HwBaseWorkflow();
		// 新的阶段
		String nextFlowStage;
		String nextFlowCodeName;
		// 判断是否满足条件
		String assignAccount = vo.getAssignAccount();
		String assignAccount2 = vo.getAssignAccount2();
		if (assignAccount.equals(assignAccount2) || !flowStage.equals("02")) {
			return ResponeResultUtil.fail(HWSystemCode.ASSIGNED);
		} else {

			// 查询下一步的工作流code
			hwBaseWorkflow = baseWorkflowService.getPresentWorkflow(flowStage, flowCode);
			nextFlowStage = hwBaseWorkflow.getWorkflowNextcode();
			nextFlowCodeName = hwBaseWorkflow.getWorkflowNextcodename();

			HwCommandTask entity = new HwCommandTask();
			entity.setAssignAccount(vo.getAssignAccount());
			entity.setAssignAccountname(vo.getAssignAccountname());
			entity.setAssignAccounttel(vo.getAssignAccounttel());
			entity.setAssignAccount2(vo.getAssignAccount2());
			entity.setAssignAccountname2(vo.getAssignAccountname2());
			entity.setAssignAccounttel2(vo.getAssignAccounttel2());
			entity.setAssignDepcode(vo.getAssignDepcode());
			entity.setAssignDepname(vo.getAssignDepname());
			// entity.setAssignStatetime(new
			// Timestamp(System.currentTimeMillis()));
			entity.setFlowStage(nextFlowStage);
			Integer update = hwCommandTaskMapper.update(entity, wrapper);
			if (update != 1) {
				return ResponeResultUtil.fail(HWSystemCode.FAIL);
			}

			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(hwBaseWorkflow.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(hwBaseWorkflow.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(hwBaseWorkflow.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(hwBaseWorkflow.getWorkflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname("指派");
			hwCommandWorkflow.setfAccount(vo.getfAccount());
			hwCommandWorkflow.setfFromdepcode(vo.getfFromdepcode());
			hwCommandWorkflow.setfFromdepname(vo.getfFromdepname());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			// hwCommandWorkflow.setCommandworkflowContent(vo.getTaskContent());
			hwCommandWorkflow.setObjectId(vo.getTaskId());
			hwCommandWorkflow.setWorkflowNextcode(nextFlowStage);
			hwCommandWorkflow.setWorkflowNextcodename(nextFlowCodeName);

			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				throw new HWSystemException();
			}
			// 创建各阶段审批操作过程
			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		}

	}

	// 完结审核
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> theEnd(StepInfoVO vo) {

		Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
		wrapper.eq("Task_ID", vo.getTaskId());

		HwCommandTask hwCommandTask = hwCommandTaskMapper.selectById(vo.getTaskId());
		String flowStage = hwCommandTask.getFlowStage();
		String flowCode = hwCommandTask.getFlowCode();
		String folderId = RandomNumberUtil.getNumber();
		// 判断是否满足条件
		if (!flowStage.equals("07")) {
			return ResponeResultUtil.fail(HWSystemCode.THE_END);
		} else {

			String nextFlowStage = vo.getWorkflowNextcode();
			String nextFlowCodeName = vo.getWorkflowNextname();
			Integer isStagestate = vo.getIsStagestate();
			HwCommandTask entity = new HwCommandTask();
			if (vo.getWorkflowDoresult() == 0) {
				entity.setTaskEndtime(new Timestamp(System.currentTimeMillis()));
				entity.setTaskEndaccount(vo.getfAccount());
				entity.setTaskEnddepcode(vo.getDeptCode());
				entity.setTaskEnddepname(vo.getDeptName());
				entity.setTaskContent(vo.getContent());
				entity.setFlowStage(nextFlowStage);
				entity.setTaskEndfile(folderId);
				entity.setIsStagestate(isStagestate);
				Integer update = hwCommandTaskMapper.update(entity, wrapper);
				if (update != 1) {
					throw new HWSystemException();
				}
			} else {
				entity.setFlowStage(nextFlowStage);
				entity.setIsStagestate(isStagestate);
				Integer update = hwCommandTaskMapper.update(entity, wrapper);
				if (update != 1) {
					throw new HWSystemException();
				}
			}
			// 附件新增
			List<FileInfo> fileInfoList = vo.getFileInfoList();
			int i = 0;
			for (FileInfo fileInfo : fileInfoList) {
				++i;
				HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
				hwBaseAnnexesfile.setFileMoudletype("ZHDDFILE指挥调度");
				hwBaseAnnexesfile.setFileName("完结附件" + String.valueOf(i));
				hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
				hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
				hwBaseAnnexesfile.setfCreateusername(vo.getfAccount());
				hwBaseAnnexesfile.setfFolderid(folderId);
				hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
				hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
				hwBaseAnnexesfile.setFileType(fileInfo.getFileType());
				Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
				if (insert != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			}
			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(vo.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(vo.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(vo.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(vo.getWordflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
			hwCommandWorkflow.setfAccount(vo.getLoginUser());
			hwCommandWorkflow.setfFromdepcode(vo.getDeptCode());
			hwCommandWorkflow.setfFromdepname(vo.getDeptName());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			hwCommandWorkflow.setCommandworkflowContent(vo.getContent());
			hwCommandWorkflow.setObjectId(vo.getTaskId());
			hwCommandWorkflow.setfAnnexes(folderId);
			hwCommandWorkflow.setWorkflowNextcode(nextFlowStage);
			hwCommandWorkflow.setWorkflowNextcodename(nextFlowCodeName);
			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				throw new HWSystemException();
			}
			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		}

	}

	// 移交确认
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> transferConfirmation(StepInfoVO vo) {

		HwCommandTask hwCommandTask = hwCommandTaskMapper.selectById(vo.getTaskId());
		String flowStage = hwCommandTask.getFlowStage();
		String flowCode = hwCommandTask.getFlowCode();
		// 判断是否满足条件
		if (!flowStage.equals("05")
				&& (hwCommandTask.getTaskType().equals("03") || hwCommandTask.getTaskType().equals("02"))) {
			return ResponeResultUtil.fail(HWSystemCode.TRANSFER_CONFIRMATION);
		} else {
			String nextFlowStage = vo.getWorkflowNextcode();
			String nextFlowCodeName = vo.getWorkflowNextname();
			String folderId = RandomNumberUtil.getNumber();
			Integer isStagestate = vo.getIsStagestate();
			HwCommandTask newTask = new HwCommandTask();
			// 更新条件
			Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
			wrapper.eq("Task_ID", vo.getTaskId());
			if (vo.getWorkflowDoresult() == 0) {
				newTask.setFlowStage(nextFlowStage);
				newTask.setIsStagestate(isStagestate);
				newTask.setTaskTransferfile(folderId);
				Integer update = hwCommandTaskMapper.update(newTask, wrapper);
				if (update != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			} else {
				newTask.setFlowStage(nextFlowStage);
				newTask.setIsStagestate(isStagestate);
				newTask.setTaskTransferfile(folderId);
				Integer update = hwCommandTaskMapper.update(newTask, wrapper);
				if (update != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			}
			// 附件新增

			List<FileInfo> fileInfoList = vo.getFileInfoList();
			int i = 0;
			for (FileInfo fileInfo : fileInfoList) {
				++i;
				HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
				hwBaseAnnexesfile.setFileMoudletype("ZHDDFILE指挥调度");
				hwBaseAnnexesfile.setFileName("移交确认附件" + String.valueOf(i));
				hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
				hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
				hwBaseAnnexesfile.setfCreateusername(vo.getfAccount());
				hwBaseAnnexesfile.setfFolderid(folderId);
				hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
				hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
				hwBaseAnnexesfile.setFileType(fileInfo.getFileType());
				Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
				if (insert != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			}
			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(vo.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(vo.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(vo.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(vo.getWordflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
			hwCommandWorkflow.setfAccount(vo.getLoginUser());
			hwCommandWorkflow.setfFromdepcode(vo.getDeptCode());
			hwCommandWorkflow.setfFromdepname(vo.getDeptName());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			hwCommandWorkflow.setCommandworkflowContent(vo.getContent());
			hwCommandWorkflow.setObjectId(vo.getTaskId());
			hwCommandWorkflow.setfAnnexes(folderId);
			hwCommandWorkflow.setWorkflowNextcode(nextFlowStage);
			hwCommandWorkflow.setWorkflowNextcodename(nextFlowCodeName);

			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				throw new HWSystemException();
			}
			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		}

	}

	// 上报视频
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> reportTheVideo(CommandTaskCountyVo vo) {

		Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
		wrapper.eq("Task_ID", vo.getTaskId());

		HwCommandTask hwCommandTask = hwCommandTaskMapper.selectById(vo.getTaskId());
		// 当前阶段
		String flowStage = hwCommandTask.getFlowStage();
		String flowCode = hwCommandTask.getFlowCode();

		// 判断是否满足条件
		if (!flowStage.equals("07")
				&& (hwCommandTask.getTaskType().equals("03") || hwCommandTask.getTaskType().equals("02"))) {
			return ResponeResultUtil.fail(HWSystemCode.REPORT_THE_VIDEO);
		} else {
			String folderId = RandomNumberUtil.getNumber();
			// 附件表新增
			List<FileInfo> fileInfoList = vo.getFileInfoList();
			int i = 0;
			for (FileInfo fileInfo : fileInfoList) {
				++i;
				HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
				hwBaseAnnexesfile.setFileMoudletype("ZHDDFILE指挥调度");
				hwBaseAnnexesfile.setFileName("视频附件" + String.valueOf(i));
				hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
				hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
				hwBaseAnnexesfile.setfCreateusername(vo.getfCreateusername());
				hwBaseAnnexesfile.setfFolderid(folderId);
				hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
				hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
				hwBaseAnnexesfile.setFileType(fileInfo.getFileType());

				Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
				if (insert != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}

			}
			HwCommandTask entity = new HwCommandTask();
			entity.setTaskType(vo.getTaskType());
			// 创建基础工作流
			HwBaseWorkflow hwBaseWorkflow = baseWorkflowService.getPresentWorkflow(flowStage, flowCode);
			entity.setFlowStage(hwBaseWorkflow.getWorkflowCode());
			entity.setTaskVideofile(folderId);

			Integer update = hwCommandTaskMapper.update(entity, wrapper);
			if (update != 1) {
				throw new HWSystemException();
			}
			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(hwBaseWorkflow.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(hwBaseWorkflow.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(hwBaseWorkflow.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(hwBaseWorkflow.getWorkflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname("上报视频");
			hwCommandWorkflow.setfAccount(vo.getfAccount());
			hwCommandWorkflow.setfFromdepcode(vo.getfFromdepcode());
			hwCommandWorkflow.setfFromdepname(vo.getfFromdepname());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			// hwCommandWorkflow.setCommandworkflowContent(vo.getTaskContent());
			hwCommandWorkflow.setObjectId(vo.getTaskId());
			hwCommandWorkflow.setfAnnexes(folderId);
			hwCommandWorkflow.setWorkflowNextcode(hwBaseWorkflow.getWorkflowNextcode());
			hwCommandWorkflow.setWorkflowNextcodename(hwBaseWorkflow.getWorkflowCodename());
			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				throw new HWSystemException();
			}
			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		}

	}

	// 详情
	public Map<String, Object> queryDetails(String fid) {

		HashMap<String, Object> result = new HashMap<String, Object>();
		// 超重数据
		HwDataOverrunstationOverweight weight = dataOverrunstationOverweightMapper.selectById(fid);
		result.put("weight", weight);
		// hwSupervisionMapper.selectById(id);

		// 指挥调度(基础信息+完结信息)
		HwCommandTask entity = new HwCommandTask();
		entity.setfId(fid);
		HwCommandTask commandTask = hwCommandTaskMapper.selectOne(entity);
		result.put("task", commandTask);

		List<HwCommandTaskfeedback> hwCommandTaskfeedbacks = null;
		List<HwSupervision> vision = null;
		if (commandTask != null) {
			// 指挥调度反馈信息
			Wrapper<HwCommandTaskfeedback> visionWra = new EntityWrapper<HwCommandTaskfeedback>();
			visionWra.eq("Task_ID", commandTask.getTaskId());
			hwCommandTaskfeedbacks = hwCommandTaskfeedbackMapper.selectList(visionWra);

			// 称重督导
			Wrapper<HwSupervision> visionWrapper = new EntityWrapper<>();
			visionWrapper.eq("F_FromObjectID", commandTask.getTaskId());
			vision = hwSupervisionMapper.selectList(visionWrapper);
		}
		result.put("taskfeedbacks", hwCommandTaskfeedbacks);
		result.put("supervision", vision);

		// 执法数据
		// 案件信息(查最新的数据)
		Wrapper<HwCaseMain> hwmin = new EntityWrapper<HwCaseMain>();
		hwmin.eq("F_OverrunID", fid).orderBy("F_CL_CheckTime", false);
		List<HwCaseMain> hwCaseMains = hwCaseMainMapper.selectList(hwmin);
		result.put("casemain", hwCaseMains);

		List<HwCaseSrccom> hwCaseSrccoms = null;
		List<HwCasePoliceoper> hwCasePoliceopers = null;
		HwCommandTask caseTask = null;
		if (hwCaseMains != null && !hwCaseMains.isEmpty()) {

			String Caseid = hwCaseMains.get(0).getfCaseid();
			// 源头倒查表
			Wrapper<HwCaseSrccom> caseSrccom = new EntityWrapper<HwCaseSrccom>();
			caseSrccom.eq("F_OverrunID", fid).eq("F_MainId", Caseid).orderBy("F_OpserTime", false);
			hwCaseSrccoms = hwCaseSrccomMapper.selectList(caseSrccom);
			// 交警执法
			Wrapper<HwCasePoliceoper> Policeoper = new EntityWrapper<HwCasePoliceoper>();
			Policeoper.eq("F_OverrunID", fid).eq("F_MainId", Caseid).orderBy("F_PunishDatetime", false);
			hwCasePoliceopers = hwCasePoliceoperMapper.selectList(Policeoper);
			// 执法督导
			HwCommandTask entityTask = new HwCommandTask();
			entityTask.setfId(Caseid);
			caseTask = hwCommandTaskMapper.selectOne(entityTask);
		}

		result.put("caseSrccom", hwCaseSrccoms);
		result.put("CasePolice", hwCasePoliceopers);
		result.put("caseTask", caseTask);

		return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, result);

	}

	// 指派任务执行中查询
	public Map<String, Object> assignedQuery(CommandTaskCountyVo vo) {
		// 分页
		Integer pageNum = vo.getPageNum();
		Integer pageSize = vo.getPageSize();

		PageUtils<CommandTaskCountyVo> pageUtils = new PageUtils<CommandTaskCountyVo>(pageNum, pageSize);
		// 任务描述
		String taskContent = vo.getTaskContent();
		// 时间段
		Timestamp startTime = vo.getStartTime();
		Timestamp endTime = vo.getEndTime();
		// 处理阶段执行中
		String flowStage = vo.getFlowStage();
		// 调度任务分类
		Integer taskClass = vo.getTaskClass();
		// 系统登录人所属部门
		String assignDepcode = vo.getfTypecode();
		// 当前登陆县用户的区域编码
		String areacode = vo.getfAreacode();

		// 县选中的超限站编号
		String overrunCode = vo.getFoverrunCode();
		EntityWrapper<HwCommandTask> taskWrapper = new EntityWrapper<HwCommandTask>();
		if (StringUtils.isNotBlank(taskContent)) {
			taskWrapper.like("Task_Content", taskContent);
		}
		if (startTime != null && endTime != null) {
			taskWrapper.between("F_CreateTime", startTime, endTime);
		}
		if (StringUtils.isNotBlank(overrunCode)) {
			taskWrapper.eq("F_FromDepCode", overrunCode);
		}
		if (StringUtils.isNotBlank(vo.getfTypecode())) {
			taskWrapper.eq("Assign_DepCode", vo.getfTypecode());
		}

		// 能看见本县的 ，也能看见 市指派到本县的（当前用户单位编码=反馈单位）
		taskWrapper.eq("Task_Class", 2).and().ne("Flow_Stage", "08").orderBy("F_CreateTime", false);
		List<HwCommandTask> hwCommandTaskList = hwCommandTaskMapper.selectList(taskWrapper);
		List<CommandTaskCountyVo> commandTaskCountyVoList = new ArrayList<CommandTaskCountyVo>();
		for (int i = 0; i < hwCommandTaskList.size(); i++) {
			CommandTaskCountyVo commandTaskCountyVo = new CommandTaskCountyVo();
			// 完结
			if (hwCommandTaskList.get(i).getFlowStage().equals("07")
					&& hwCommandTaskList.get(i).getfFromdepcode().equals(assignDepcode)) {
				commandTaskCountyVo.setTheEnd(1);
			}
			// 移交确认
			if (hwCommandTaskList.get(i).getFlowStage().equals("05")
					&& hwCommandTaskList.get(i).getFlowCode().equals("SJJB")) {
				commandTaskCountyVo.setTransferConfirmation(1);
			}
			// 删除
			if (!hwCommandTaskList.get(i).getFlowStage().equals("08")
					&& hwCommandTaskList.get(i).getfFromdepcode().equals(assignDepcode)) {
				commandTaskCountyVo.setAssignedDelete(1);
			}
			// 修改
			if (!hwCommandTaskList.get(i).getFlowStage().equals("08")
					&& hwCommandTaskList.get(i).getfFromdepcode().equals(assignDepcode)) {
				commandTaskCountyVo.setAssignedUpdate(1);
			}
			// 指派
			if (hwCommandTaskList.get(i).getFlowStage().equals("02")
					&& hwCommandTaskList.get(i).getFlowCode().equals("SJJB")) {
				commandTaskCountyVo.setAssigned(1);
			}
			commandTaskCountyVo.setAssignAccount(hwCommandTaskList.get(i).getAssignAccount());
			commandTaskCountyVo.setAssignAccount2(hwCommandTaskList.get(i).getAssignAccount2());
			commandTaskCountyVo.setAssignAccountname(hwCommandTaskList.get(i).getAssignAccountname());
			commandTaskCountyVo.setAssignAccountname2(hwCommandTaskList.get(i).getAssignAccountname2());
			commandTaskCountyVo.setAssignAccounttel(hwCommandTaskList.get(i).getAssignAccounttel());
			commandTaskCountyVo.setAssignAccounttel2(hwCommandTaskList.get(i).getAssignAccounttel2());
			commandTaskCountyVo.setAssignDepcode(hwCommandTaskList.get(i).getAssignDepcode());
			commandTaskCountyVo.setAssignDepname(hwCommandTaskList.get(i).getAssignDepname());
			commandTaskCountyVo.setAssignState(hwCommandTaskList.get(i).getAssignState());
			commandTaskCountyVo.setAssignStatetime(hwCommandTaskList.get(i).getAssignStatetime());
			commandTaskCountyVo.setfAccount(hwCommandTaskList.get(i).getfAccount());
			commandTaskCountyVo.setfAreacode(hwCommandTaskList.get(i).getfAreacode());
			commandTaskCountyVo.setfCreatetime(hwCommandTaskList.get(i).getfCreatetime());
			commandTaskCountyVo.setfFromdepcode(hwCommandTaskList.get(i).getfFromdepcode());
			commandTaskCountyVo.setfFromdepname(hwCommandTaskList.get(i).getfFromdepname());
			commandTaskCountyVo.setfFromdeptype(hwCommandTaskList.get(i).getfFromdeptype());
			commandTaskCountyVo.setFlowCode(hwCommandTaskList.get(i).getFlowCode());
			commandTaskCountyVo.setFlowStage(hwCommandTaskList.get(i).getFlowStage());
			commandTaskCountyVo.setIsStagestate(hwCommandTaskList.get(i).getIsStagestate());
			commandTaskCountyVo.setOverrunstationId(hwCommandTaskList.get(i).getOverrunstationId());
			commandTaskCountyVo.setTaskClass(hwCommandTaskList.get(i).getTaskClass());
			commandTaskCountyVo.setTaskContent(hwCommandTaskList.get(i).getTaskContent());
			commandTaskCountyVo.setTaskEndaccount(hwCommandTaskList.get(i).getTaskEndaccount());
			commandTaskCountyVo.setTaskEndcontent(hwCommandTaskList.get(i).getTaskEndcontent());
			commandTaskCountyVo.setTaskEnddepcode(hwCommandTaskList.get(i).getTaskEnddepcode());
			commandTaskCountyVo.setTaskEnddepname(hwCommandTaskList.get(i).getTaskEnddepname());
			commandTaskCountyVo.setTaskEndfile(hwCommandTaskList.get(i).getTaskEndfile());
			commandTaskCountyVo.setTaskEndtime(hwCommandTaskList.get(i).getTaskEndtime());
			commandTaskCountyVo.setTaskExplainfile(hwCommandTaskList.get(i).getTaskExplainfile());
			commandTaskCountyVo.setTaskId(hwCommandTaskList.get(i).getTaskId());
			commandTaskCountyVo.setTaskTransferfile(hwCommandTaskList.get(i).getTaskTransferfile());
			commandTaskCountyVo.setTaskVideofile(hwCommandTaskList.get(i).getTaskVideofile());
			commandTaskCountyVo.setTaskType(hwCommandTaskList.get(i).getTaskType());

			commandTaskCountyVoList.add(commandTaskCountyVo);

		}

		Object info = pageUtils.getPageResult(commandTaskCountyVoList);
		return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, info);
	}

	// 指派任务完结查询
	public Map<String, Object> assignedEndQuery(CommandTaskCountyVo vo) {

		// 分页
		Integer pageNum = vo.getPageNum();
		Integer pageSize = vo.getPageSize();

		PageUtils<CommandTaskCountyVo> pageUtils = new PageUtils<CommandTaskCountyVo>(pageNum, pageSize);
		// 任务描述
		String taskContent = vo.getTaskContent();
		// 时间段
		Timestamp startTime = vo.getStartTime();
		Timestamp endTime = vo.getEndTime();
		// 处理阶段执行中
		String flowStage = vo.getFlowStage();
		// 调度任务分类
		Integer taskClass = vo.getTaskClass();
		// 系统登录人所属部门
		String assignDepcode = vo.getfTypecode();
		// 当前登陆县用户的区域编码
		String areacode = vo.getfAreacode();
		// 县选中的超限站编号
		String overrunCode = vo.getFoverrunCode();

		EntityWrapper<HwCommandTask> taskWrapper = new EntityWrapper<HwCommandTask>();
		if (StringUtils.isNotBlank(taskContent)) {
			taskWrapper.like("Task_Content", taskContent);
		}
		if (startTime != null && endTime != null) {
			taskWrapper.between("F_CreateTime", startTime, endTime);
		}
		if (StringUtils.isNotBlank(overrunCode)) {
			taskWrapper.eq("F_FromDepCode", overrunCode);
		}
		if (StringUtils.isNotBlank(vo.getfTypecode())) {
			taskWrapper.eq("Assign_DepCode", vo.getfTypecode());
		}
		// 脏数据：fFromdeptype条件没起作用
		taskWrapper.eq("Task_Class", taskClass).and().eq("Flow_Stage", flowStage).orderBy("F_CreateTime", false);

		List<HwCommandTask> hwCommandTaskList = hwCommandTaskMapper.selectList(taskWrapper);
		List<CommandTaskCountyVo> commandTaskCountyVoList = new ArrayList<CommandTaskCountyVo>();
		for (int i = 0; i < hwCommandTaskList.size(); i++) {
			CommandTaskCountyVo commandTaskCountyVo = new CommandTaskCountyVo();

			commandTaskCountyVo.setAssignAccount(hwCommandTaskList.get(i).getAssignAccount());
			commandTaskCountyVo.setAssignAccount2(hwCommandTaskList.get(i).getAssignAccount2());
			commandTaskCountyVo.setAssignAccountname(hwCommandTaskList.get(i).getAssignAccountname());
			commandTaskCountyVo.setAssignAccountname2(hwCommandTaskList.get(i).getAssignAccountname2());
			commandTaskCountyVo.setAssignAccounttel(hwCommandTaskList.get(i).getAssignAccounttel());
			commandTaskCountyVo.setAssignAccounttel2(hwCommandTaskList.get(i).getAssignAccounttel2());
			commandTaskCountyVo.setAssignDepcode(hwCommandTaskList.get(i).getAssignDepcode());
			commandTaskCountyVo.setAssignDepname(hwCommandTaskList.get(i).getAssignDepname());
			commandTaskCountyVo.setAssignState(hwCommandTaskList.get(i).getAssignState());
			commandTaskCountyVo.setAssignStatetime(hwCommandTaskList.get(i).getAssignStatetime());
			commandTaskCountyVo.setfAccount(hwCommandTaskList.get(i).getfAccount());
			commandTaskCountyVo.setfAreacode(hwCommandTaskList.get(i).getfAreacode());
			commandTaskCountyVo.setfCreatetime(hwCommandTaskList.get(i).getfCreatetime());
			commandTaskCountyVo.setfFromdepcode(hwCommandTaskList.get(i).getfFromdepcode());
			commandTaskCountyVo.setfFromdepname(hwCommandTaskList.get(i).getfFromdepname());
			commandTaskCountyVo.setfFromdeptype(hwCommandTaskList.get(i).getfFromdeptype());
			commandTaskCountyVo.setFlowCode(hwCommandTaskList.get(i).getFlowCode());
			commandTaskCountyVo.setFlowStage(hwCommandTaskList.get(i).getFlowStage());
			commandTaskCountyVo.setIsStagestate(hwCommandTaskList.get(i).getIsStagestate());
			commandTaskCountyVo.setOverrunstationId(hwCommandTaskList.get(i).getOverrunstationId());
			commandTaskCountyVo.setTaskClass(hwCommandTaskList.get(i).getTaskClass());
			commandTaskCountyVo.setTaskContent(hwCommandTaskList.get(i).getTaskContent());
			commandTaskCountyVo.setTaskEndaccount(hwCommandTaskList.get(i).getTaskEndaccount());
			commandTaskCountyVo.setTaskEndcontent(hwCommandTaskList.get(i).getTaskEndcontent());
			commandTaskCountyVo.setTaskEnddepcode(hwCommandTaskList.get(i).getTaskEnddepcode());
			commandTaskCountyVo.setTaskEnddepname(hwCommandTaskList.get(i).getTaskEnddepname());
			commandTaskCountyVo.setTaskEndfile(hwCommandTaskList.get(i).getTaskEndfile());
			commandTaskCountyVo.setTaskEndtime(hwCommandTaskList.get(i).getTaskEndtime());
			commandTaskCountyVo.setTaskExplainfile(hwCommandTaskList.get(i).getTaskExplainfile());
			commandTaskCountyVo.setTaskId(hwCommandTaskList.get(i).getTaskId());
			commandTaskCountyVo.setTaskTransferfile(hwCommandTaskList.get(i).getTaskTransferfile());
			commandTaskCountyVo.setTaskVideofile(hwCommandTaskList.get(i).getTaskVideofile());
			commandTaskCountyVo.setTaskType(hwCommandTaskList.get(i).getTaskType());

			commandTaskCountyVoList.add(commandTaskCountyVo);

		}
		Object info = pageUtils.getPageResult(commandTaskCountyVoList);
		return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, info);
	}

	// 指派任务创建
	public Map<String, Object> assignedInsert(CommandTaskCountyVo vo) {

		String taskId = RandomNumberUtil.getNumber();
		HwCommandTask hwCommandTask = new HwCommandTask();
		hwCommandTask.setTaskId(taskId);
		hwCommandTask.setAssignAccount(vo.getAssignAccount());
		hwCommandTask.setAssignAccount2(vo.getAssignAccount2());
		hwCommandTask.setAssignAccountname(vo.getAssignAccountname());
		hwCommandTask.setAssignAccountname2(vo.getAssignAccountname2());
		hwCommandTask.setAssignAccounttel(vo.getAssignAccounttel());
		hwCommandTask.setAssignAccounttel2(vo.getAssignAccounttel2());
		hwCommandTask.setAssignDepcode(vo.getAssignDepcode());
		hwCommandTask.setAssignDepname(vo.getfFromdepname());
		hwCommandTask.setAssignState(0);
		// hwCommandTask.setAssignStatetime(new
		// Timestamp(System.currentTimeMillis()));
		hwCommandTask.setfId(vo.getfId());
		hwCommandTask.setfAreacode(vo.getfAreacode());
		hwCommandTask.setfAccount(vo.getfAccount());
		hwCommandTask.setTaskClass(2);
		hwCommandTask.setTaskType(vo.getTaskType());
		hwCommandTask.setTaskContent(vo.getTaskContent());
		hwCommandTask.setfAreacode(vo.getfAreacode());
		hwCommandTask.setfCreatetime(new Timestamp(System.currentTimeMillis()));
		hwCommandTask.setfFromdeptype(2);
		hwCommandTask.setfFromdepcode(vo.getfFromdepcode());
		hwCommandTask.setfFromdepname(vo.getfFromdepname());
		hwCommandTask.setFlowCode("XJJB");
		hwCommandTask.setIsStagestate(0);

		HwBaseWorkflow startBaseWorkflow = baseWorkflowService.getStartBaseWorkflow("XJJB");
		hwCommandTask.setFlowStage(startBaseWorkflow.getWorkflowNextcode());

		Integer insert = hwCommandTaskMapper.insert(hwCommandTask);
		if (insert != 1) {
			return ResponeResultUtil.fail(HWSystemCode.FAIL);
		}

		// 创建各阶段审批操作过程
		HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
		hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
		hwCommandWorkflow.setWorkflowModule(startBaseWorkflow.getWorkflowModule());
		hwCommandWorkflow.setWorkflowType("XJJB");
		hwCommandWorkflow.setWorkflowCode(startBaseWorkflow.getWorkflowCode());
		hwCommandWorkflow.setWorkflowCodename(startBaseWorkflow.getWorkflowCodename());
		hwCommandWorkflow.setCommandworkflowButtonname("指派任务创建");
		hwCommandWorkflow.setfAccount(vo.getfAccount());
		hwCommandWorkflow.setfFromdepcode(vo.getfFromdepcode());
		hwCommandWorkflow.setfFromdepname(vo.getfFromdepname());
		hwCommandWorkflow.setCommandworkflowDatatime(new Date());
		// hwCommandWorkflow.setCommandworkflowContent(vo.getTaskContent());
		hwCommandWorkflow.setObjectId(taskId);
		hwCommandWorkflow.setWorkflowNextcode(startBaseWorkflow.getWorkflowNextcode());
		hwCommandWorkflow.setWorkflowNextcodename(startBaseWorkflow.getWorkflowNextcodename());
		// 向各阶段审批操作过程表插入数据
		boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
		if (!success) {
			throw new HWSystemException();
		}
		return ResponeResultUtil.success(HWSystemCode.SUCCESS);
	}

	// 指派任务删除（根据taskid查数据库）
	public Map<String, Object> assignedDelete(CommandTaskCountyVo vo) {

		String taskId = vo.getTaskId();

		HwCommandTask hct = hwCommandTaskMapper.selectById(taskId);
		if (!hct.getFlowStage().equals("08") && hct.getfFromdepcode().equals(vo.getfTypecode())) {

			Integer delete = hwCommandTaskMapper.deleteById(taskId);
			if (delete != 1) {
				return ResponeResultUtil.fail(HWSystemCode.FAIL);
			}

			// 查询下一步的工作流code
			HwBaseWorkflow hwBaseWorkflow = baseWorkflowService.getPresentWorkflow(hct.getFlowStage(),
					hct.getFlowCode());

			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(hwBaseWorkflow.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(hwBaseWorkflow.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(hwBaseWorkflow.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(hwBaseWorkflow.getWorkflowCodename());
			hwCommandWorkflow.setfAccount(vo.getfAccount());
			hwCommandWorkflow.setCommandworkflowButtonname("指派任务删除");
			hwCommandWorkflow.setfFromdepcode(vo.getfFromdepcode());
			hwCommandWorkflow.setfFromdepname(vo.getfFromdepname());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			// hwCommandWorkflow.setCommandworkflowContent(vo.getTaskContent());
			hwCommandWorkflow.setObjectId(vo.getTaskId());
			hwCommandWorkflow.setWorkflowNextcode("99");
			hwCommandWorkflow.setWorkflowNextcodename("");

			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (!success) {
				throw new HWSystemException();
			}
			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		} else {
			return ResponeResultUtil.fail(HWSystemCode.THE_FOUNDER_OF);
		}
	}

	// 指派任务中修改（根据taskid查数据库）
	public Map<String, Object> assignedUpdate(CommandTaskCountyVo vo) {

		String taskId = vo.getTaskId();

		HwCommandTask hct = hwCommandTaskMapper.selectById(taskId);
		if (!hct.getFlowStage().equals("08") && hct.getfFromdepcode().equals(vo.getfTypecode())) {

			Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
			wrapper.eq("Task_ID", taskId);

			HwCommandTask hwCommandTask = new HwCommandTask();

			hwCommandTask.setTaskContent(vo.getTaskContent());

			Integer update = hwCommandTaskMapper.update(hwCommandTask, wrapper);
			if (update != 1) {
				return ResponeResultUtil.fail(HWSystemCode.FAIL);
			}

			// 查询下一步的工作流code
			HwBaseWorkflow hwBaseWorkflow = baseWorkflowService.getPresentWorkflow(hct.getFlowStage(),
					hct.getFlowCode());

			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(hwBaseWorkflow.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(hwBaseWorkflow.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(hwBaseWorkflow.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(hwBaseWorkflow.getWorkflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname("指派任务修改");
			hwCommandWorkflow.setfAccount(vo.getfAccount());
			hwCommandWorkflow.setfFromdepcode(vo.getfFromdepcode());
			hwCommandWorkflow.setfFromdepname(vo.getfFromdepname());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			// hwCommandWorkflow.setCommandworkflowContent(vo.getTaskContent());
			hwCommandWorkflow.setObjectId(vo.getTaskId());
			hwCommandWorkflow.setWorkflowNextcode("99");
			hwCommandWorkflow.setWorkflowNextcodename("");

			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (!success) {
				throw new HWSystemException();
			}
			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		} else {
			return ResponeResultUtil.fail(HWSystemCode.THE_FOUNDER_OF);
		}
	}

	// 指派任务中完结（根据taskid查数据库）
	public Map<String, Object> assignedEnd(StepInfoVO vo) {

		String taskId = vo.getTaskId();

		HwCommandTask hct = hwCommandTaskMapper.selectById(taskId);
		if (hct.getFlowStage().equals("07") && hct.getTaskClass() == 2
				&& hct.getfFromdepcode().equals(vo.getDeptCode())) {

			Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
			wrapper.eq("Task_ID", taskId);
			String nextFlowStage = vo.getWorkflowNextcode();
			String nextFlowCodeName = vo.getWorkflowNextname();
			Integer isStagestate = vo.getIsStagestate();
			// 附件id
			String folderId = RandomNumberUtil.getNumber();
			HwCommandTask hwCommandTask = new HwCommandTask();
			if (vo.getWorkflowDoresult() == 0) {
				hwCommandTask.setTaskEndtime(new Timestamp(System.currentTimeMillis()));

				hwCommandTask.setTaskEndaccount(vo.getfAccount());
				hwCommandTask.setTaskEnddepcode(vo.getDeptCode());
				hwCommandTask.setTaskEnddepname(vo.getDeptName());
				hwCommandTask.setTaskContent(vo.getTaskContent());
				hwCommandTask.setTaskEndfile(folderId);
				hwCommandTask.setFlowStage(nextFlowStage);
				hwCommandTask.setIsStagestate(isStagestate);
				hwCommandTask.setTaskEndcontent(vo.getContent());
				Integer update = hwCommandTaskMapper.update(hwCommandTask, wrapper);
				if (update != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			} else {
				hwCommandTask.setFlowStage(nextFlowStage);
				hwCommandTask.setIsStagestate(isStagestate);
				Integer update = hwCommandTaskMapper.update(hwCommandTask, wrapper);
				if (update != 1) {
					throw new HWSystemException();
				}
			}

			// 附件新增
			List<FileInfo> fileInfoList = vo.getFileInfoList();
			int i = 0;
			for (FileInfo fileInfo : fileInfoList) {
				++i;
				HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
				hwBaseAnnexesfile.setFileMoudletype("ZHDDFILE指挥调度");
				hwBaseAnnexesfile.setFileName("完结附件" + String.valueOf(i));
				hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
				hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
				hwBaseAnnexesfile.setfCreateusername(vo.getfAccount());
				hwBaseAnnexesfile.setfFolderid(folderId);
				hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
				hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
				hwBaseAnnexesfile.setFileType(fileInfo.getFileType());
				Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
				if (insert != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			}
			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(vo.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(vo.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(vo.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(vo.getWordflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
			hwCommandWorkflow.setfAccount(vo.getLoginUser());
			hwCommandWorkflow.setfFromdepcode(vo.getDeptCode());
			hwCommandWorkflow.setfFromdepname(vo.getDeptName());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			hwCommandWorkflow.setCommandworkflowContent(vo.getContent());
			hwCommandWorkflow.setObjectId(vo.getTaskId());
			hwCommandWorkflow.setfAnnexes(folderId);
			hwCommandWorkflow.setWorkflowNextcode(nextFlowStage);
			hwCommandWorkflow.setWorkflowNextcodename(nextFlowCodeName);
			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				throw new HWSystemException();
			}

			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		} else {
			return ResponeResultUtil.fail(HWSystemCode.THE_FOUNDER_OF);
		}
	}

	// 指派任务中确认（F_FromDepType=1执行逻辑 根据taskid查数据库）
	public Map<String, Object> assignedConfirm(StepInfoVO vo) {

		String taskId = vo.getTaskId();

		HwCommandTask hct = hwCommandTaskMapper.selectById(taskId);
		if (hct.getFlowStage().equals("05") && hct.getTaskClass() == 2 && hct.getFlowCode().equals("SJJB")) {

			Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
			wrapper.eq("Task_ID", taskId);
			String nextFlowStage = vo.getWorkflowNextcode();
			String nextFlowCodeName = vo.getWorkflowNextname();
			Integer isStagestate = vo.getWorkflowDoresult();
			// 附件id
			String folderId = RandomNumberUtil.getNumber();
			HwCommandTask hwCommandTask = new HwCommandTask();
			if (vo.getWorkflowDoresult() == 0) {
				hwCommandTask.setFlowStage(nextFlowStage);
				hwCommandTask.setIsStagestate(isStagestate);
				hwCommandTask.setTaskExplainfile(folderId);
				Integer update = hwCommandTaskMapper.update(hwCommandTask, wrapper);
				if (update != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}

			} else {
				hwCommandTask.setFlowStage(nextFlowStage);
				hwCommandTask.setIsStagestate(isStagestate);
				Integer update = hwCommandTaskMapper.update(hwCommandTask, wrapper);
				if (update != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			}

			// 附件新增
			List<FileInfo> fileInfoList = vo.getFileInfoList();
			int i = 0;
			for (FileInfo fileInfo : fileInfoList) {
				++i;
				HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
				hwBaseAnnexesfile.setFileMoudletype("ZHDDFILE指挥调度");
				hwBaseAnnexesfile.setFileName("确认附件" + String.valueOf(i));
				hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
				hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
				hwBaseAnnexesfile.setfCreateusername(vo.getfAccount());
				hwBaseAnnexesfile.setfFolderid(folderId);
				hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
				hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
				hwBaseAnnexesfile.setFileType(fileInfo.getFileType());
				Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
				if (insert != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			}
			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(vo.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(vo.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(vo.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(vo.getWordflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
			hwCommandWorkflow.setfAccount(vo.getLoginUser());
			hwCommandWorkflow.setfFromdepcode(vo.getDeptCode());
			hwCommandWorkflow.setfFromdepname(vo.getDeptName());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			hwCommandWorkflow.setCommandworkflowContent(vo.getContent());
			hwCommandWorkflow.setObjectId(vo.getTaskId());
			hwCommandWorkflow.setfAnnexes(folderId);
			hwCommandWorkflow.setWorkflowNextcode(nextFlowStage);
			hwCommandWorkflow.setWorkflowNextcodename(nextFlowCodeName);
			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				throw new HWSystemException();
			}
			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		} else {
			return ResponeResultUtil.fail(HWSystemCode.THE_FOUNDER_OF);
		}
	}

	// 指派任务
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> assignedTasks(CommandTaskCountyVo vo) {

		Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
		wrapper.eq("Task_ID", vo.getTaskId());
		HwCommandTask hwCommandTask = hwCommandTaskMapper.selectById(vo.getTaskId());
		String flowStage = hwCommandTask.getFlowStage();
		String flowCode = hwCommandTask.getFlowCode();
		// 创建基础工作流
		HwBaseWorkflow hwBaseWorkflow = new HwBaseWorkflow();
		// 新的阶段
		String nextFlowStage;
		String nextFlowCodeName;
		// 判断是否满足条件
		String assignAccount = vo.getAssignAccount();
		String assignAccount2 = vo.getAssignAccount2();
		if (assignAccount.equals(assignAccount2) || !flowStage.equals("02")
				|| !hwCommandTask.getFlowCode().equals("SJJB")) {
			return ResponeResultUtil.fail(HWSystemCode.ASSIGNED);
		} else {

			// 查询下一步的工作流code
			hwBaseWorkflow = baseWorkflowService.getPresentWorkflow(flowStage, flowCode);
			nextFlowStage = hwBaseWorkflow.getWorkflowNextcode();
			nextFlowCodeName = hwBaseWorkflow.getWorkflowNextcodename();

			HwCommandTask entity = new HwCommandTask();
			entity.setAssignAccount(vo.getAssignAccount());
			entity.setAssignAccountname(vo.getAssignAccountname());
			entity.setAssignAccounttel(vo.getAssignAccounttel());
			entity.setAssignAccount2(vo.getAssignAccount2());
			entity.setAssignAccountname2(vo.getAssignAccountname2());
			entity.setAssignAccounttel2(vo.getAssignAccounttel2());
			entity.setAssignDepcode(vo.getAssignDepcode());
			entity.setAssignDepname(vo.getAssignDepname());
			// entity.setAssignStatetime(new
			// Timestamp(System.currentTimeMillis()));
			entity.setFlowStage(nextFlowStage);
			Integer update = hwCommandTaskMapper.update(entity, wrapper);
			if (update != 1) {
				return ResponeResultUtil.fail(HWSystemCode.FAIL);
			}

			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(hwBaseWorkflow.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(hwBaseWorkflow.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(hwBaseWorkflow.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(hwBaseWorkflow.getWorkflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname("指派");
			hwCommandWorkflow.setfAccount(vo.getfAccount());
			hwCommandWorkflow.setfFromdepcode(vo.getfFromdepcode());
			hwCommandWorkflow.setfFromdepname(vo.getfFromdepname());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			// hwCommandWorkflow.setCommandworkflowContent(vo.getTaskContent());
			hwCommandWorkflow.setObjectId(vo.getTaskId());
			hwCommandWorkflow.setWorkflowNextcode(nextFlowStage);
			hwCommandWorkflow.setWorkflowNextcodename(nextFlowCodeName);

			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				throw new HWSystemException();
			}
			// 创建各阶段审批操作过程
			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		}

	}

}
